<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <meta charset="UTF-8">
    <title>汇总</title>
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../css/global.css" media="all"/>

    <style >
        .form-filter-wrap .form-inline .layui-form-label {
            width: 160px;
        }
        .table th {
            text-align: center;
        }
        .table tfoot tr th {
            text-align: left;
        }
        .align_right {
            text-align: right;
        }
        .align_center {
            text-align: center;
        }
    </style>

</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 page-container">
    <header class="form-filter-wrap">
        <form class="layui-form form-inline" onsubmit="return false">
            <div class="form-group">
                <div class="form-filter">
                    <div style="margin: 5px 0">

                        <div class="form-inner">
                            <label class="layui-form-label">巡察年度：</label>
                            <div class="layui-input-inline">
                                <select multiple lay-omit id="startPatrolTime">
                                    <option></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-inner">
                            <label class="layui-form-label">问题类别：</label>
                            <div class="layui-input-inline">
                                <select multiple lay-omit id="questionType">
                                    <option></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-inner">
                            <label class="layui-form-label">单位：</label>
                            <div class="layui-input-inline">
                                <select multiple lay-omit id="branch" lay-search>
                                    <option></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-inner">
                            <label class="layui-form-label">督察人员：</label>
                            <div class="layui-input-inline">
                                <select multiple lay-omit id="oversee">
                                    <option></option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div style="margin: 5px 0">

                        <div class="form-inner">
                            <label class="layui-form-label">整改进度：</label>
                            <div class="layui-input-inline">
                                <select multiple lay-omit id="questionStatus">
                                    <option></option>
                                </select>
                            </div>
                        </div>
                        <button style="margin-left: 50px" id="searchBt" class="layui-btn layui-btn-sm"><i
                                class="layui-icon">&#xe615;</i>搜索
                        </button>
                        <button class="layui-btn layui-btn-sm" onclick="excel()">
                            <i class="layui-icon"></i> 导出Excel
                        </button>
                    </div>

                </div>
            </div>

        </form>
    </header>

    <div class="content-container" style="top: 90px">
        <div class="widget-body no-padding">
            <table id="dt-table" class="table table-striped table-bordered table-hover classsName " style="width: 100%">
                <thead>
                <tr>
                    <th><input type='checkbox' id='checkAll'/></th>
                    <th >巡察单位</th>
                    <th style="display: none"></th>
                    <th >巡察年度</th>
                    <th >督察人员</th>
                    <th >问题类别</th>
                    <th >问题项</th>
                    <th >整改进度</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
<!--附件查看-->
<div id="hidden1" lay-filter="hidden1" style="display: none">
    <table id="department_result" lay-filter="department_result"></table>
</div>

<script type="text/html" id="hidden1-table-tool">
    <a class="layui-btn layui-btn-xs" lay-event="select">选择</a>
</script>


<div id="openProductBox" style="display: none; padding: 10px;">
    <table id="openProductTable" lay-filter="openProductTable"></table>
</div>
<div id="openProductBox2" style="display: none; padding: 10px;">
    <button type="button" lay-event="del" class="layui-btn layui-btn-sm" id="down"><i class="layui-icon"></i>查看</button>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>


<script type="text/html" id="itemTpl">
    {{# if( d.type == 2 && d.delated == 0){ }}
    <button type="button" lay-event="del1" class="layui-btn layui-btn-sm" id="del1"><i class="layui-icon"></i>删除
    </button>
    {{# } }}

    {{# if( d.type == 3 && d.delated == 1){ }}
    <button type="button" lay-event="del2" class="layui-btn layui-btn-sm" id="del2"><i class="layui-icon"></i>删除
    </button>
    {{# } }}
</script>

<script type="text/javascript" src="../../js/libs/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/plugin/fnReloadAjax.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/dict.js"></script>
<script type="text/javascript" src="../../js/plugin/jquery-download.js"></script>
<script type="text/javascript">
    var userId = $('.header-demo .layui-nav .layui-nav-item a span#userId', parent.document).text();
    /*公司*/
    layui.use(['layer', 'form', 'jquery'], function () {
        var form = layui.form;
        $.ajax({
            url: '/dropDown/getBranch',
            dataType: 'json',
            type: 'post',
            success: function (data) {
                // 使用循环遍历，给下拉列表赋值
                $.each(data, function (index, value) {
                    if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/8./i)=="8.") {
                        var option = document.createElement("option");
                        option.setAttribute("value",value.value);
                        option.innerText = value.value;
                        document.getElementById('branch').appendChild(option);
                    } else {
                        $('#branch').append(new Option(value.value, value.key));// 下拉菜单里添加元素
                    }


                });
                form.render();//重新渲染 固定写法
            }
        })
            /*年度*/
            , $.ajax({
            url: '/dropDown/getYear',
            dataType: 'json',
            type: 'post',
            success: function (data) {
                // 使用循环遍历，给下拉列表赋值
                $.each(data, function (index, value) {
                    if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/8./i)=="8.") {
                        var option = document.createElement("option");
                        option.setAttribute("value",value.value);
                        option.innerText = value.value;
                        document.getElementById('startPatrolTime').appendChild(option);
                    } else {
                        $('#startPatrolTime').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                    }

                });
                form.render();//重新渲染 固定写法
            }
        })/*整改进度*/
            , $.ajax({
            url: '/dropDown/getSchedule',
            dataType: 'json',
            type: 'post',
            success: function (data) {
                // 使用循环遍历，给下拉列表赋值
                $.each(data, function (index, value) {
                    if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/8./i)=="8.") {
                        var option = document.createElement("option");
                        option.setAttribute("value",value.value);
                        option.innerText = value.value;
                        document.getElementById('questionStatus').appendChild(option);
                    } else {
                        $('#questionStatus').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                    }

                });
                form.render();//重新渲染 固定写法
            }
        })/*督察人员*/
            , $.ajax({
            url: '/dropDown/getOversee',
            dataType: 'json',
            type: 'post',
            success: function (data) {
                // 使用循环遍历，给下拉列表赋值
                $.each(data, function (index, value) {
                    if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/8./i)=="8.") {
                        var option = document.createElement("option");
                        option.setAttribute("value",value.value);
                        option.innerText = value.value;
                        document.getElementById('oversee').appendChild(option);
                    } else {
                        $('#oversee').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                    }

                });
                form.render();//重新渲染 固定写法
            }
        })
            ,
            /*问题类别*/
            $.ajax({
                url: '/dropDown/getQuestion',
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    // 使用循环遍历，给下拉列表赋值
                    $.each(data, function (index, value) {
                        if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/8./i)=="8.") {
                            var option = document.createElement("option");
                            option.setAttribute("value",value.value);
                            option.innerText = value.value;
                            document.getElementById('questionType').appendChild(option);
                        } else {
                            $('#questionType').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                        }

                    });
                    form.render();//重新渲染 固定写法
                }
            })


    });

    var example;

    function init() {
        example =
            $('#dt-table').DataTable({
                    retrieve: true,
                    "searching": false,
                    "processing": false,
                    "serverSide": true,
                    "ordering": false,
                    "scrollX": false,
                    "scrollY": false,

                    "scrollCollapse": true,
                    'iDisplayLength': 8,
                    "language": {
                        "url": "/js/plugin/datatables/Chinese.lang"
                    },
                    "ajax": {
                        "url": "/mOverseeQuestions/allList",
                        "type": "get",
                        "data": function (d) {
                            if ($("#questionType").val() != null) {
                                d.questionType = JSON.stringify($("#questionType").val());
                            }
                            if ($("#startPatrolTime").val() != null) {
                                d.startPatrolTime = JSON.stringify($("#startPatrolTime").val());
                            }
                            if ($("#branch").val() != null) {
                                d.branchId = JSON.stringify($("#branch").val());
                            }
                            if ($("#oversee").val() != null) {
                                d.oversee = JSON.stringify($("#oversee").val());
                            }

                        },
                        "error": function (xhr, textStatus, errorThrown) {
                            var msg = xhr.responseText;
                            console.log(msg);
                            var response = JSON.parse(msg);
                            var code = response.code;
                            var message = response.message;
                            if (code == 400) {
                                layer.msg(message);
                            } else if (code == 401) {
                                localStorage.removeItem("token");
                                layer.msg("token过期，请先登录", {shift: -1, time: 1000}, function () {
                                    location.href = '/login.html';
                                });
                            } else if (code == 403) {
                                console.log("未授权:" + message);
                                layer.msg('未授权');
                            } else if (code == 500) {
                                layer.msg('系统错误：' + message);
                            }
                        }
                    },
                    "dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'table-bottom col-sm-10 col-xs-12 hidden-xs'i><'table-bottom col-xs-12 col-sm-10' p v>>",
                    "columns": [
                        {
                            "data": "id",
                            "render": function (data, type, row, meta) {
                                return "<input type='checkbox' class='table-checkbox' onclick='childclick(" + data + ")' name='childclick' id='' value=" + data + " />";
                            }
                        },
                        {"width":"150",
                            "data": "branch",
                            "defaultContent": "",
                            "render": function (data, type, row, meta) {
                                return "<a href='javascript:;' ><cite>" + data + "</cite></a>"
                            }
                        },
                        {"data": "branchId", "defaultContent": "", "visible": false},
                        {"width":"80","data": "startPatrolTime", "defaultContent": ""},
                        {"width":"100","data": "oversee", "defaultContent": ""},
                        {"width":"250","data": "questionType", "defaultContent": ""},
                        {
                            "data": "question", "defaultContent": "",
                            render: function (data, type, row, meta) {
                                if (data) {
                                    if (data.length > 50) {
                                        return '<div style="text-align: left">'+data.substr(0, 50) + " <a style='color: #1E9FFF ;font-size: 8px' href='javascript:void(0);' onclick='javascript:searchBtn3(\"" + data + "\", \"" + '问题项' + "\")' ><i style='font-weight: bold' class='layui-icon layui-icon-search'></i></a> "+'</div>';
                                    } else {
                                        return '<div style="text-align: left">'+data +'</div>';

                                    }
                                } else {
                                    return "";
                                }
                            }

                        },
                        {"width":"100","data": "questionStatus", "defaultContent": ""}
                    ],
                    "order": [[0, "asc"]]
                }
            );
        return example
    }


    function searchBtn3(id, title) {
        layer.open({
            type: 1
            , title: '<div class="layui-icon" style="font-weight: bold; text-align: center">' + title + '</div>'
            , area: ["600px", ""]
            , content: '<div style="padding: 20px;font-size:18px;line-height:30px;">' + id + '</div>'
            , btnAlign: 'c' //按钮居中
            , shade: 0.3 //不显示遮罩
            , shadeClose: false
            , yes: function () {
                layer.closeAll();
            }
        });

    }


    var sendVar = {};

    function sendDetailData() {
        return sendVar
    }

    $(document).on('dblclick', '#dt-table tbody tr', function () {
        parent.$(window.parent.document).find('[lay-id=101]').click();
        sendVar = init().row(this).data();
        setTimeout(function () {
            sendVar = null;
        }, 5000)
    });


    function del(id) {
        layer.confirm('确定要删除吗？', {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                type: 'delete',
                url: '/mOverseeQuestions/' + id,
                success: function (data) {
                    example.ajax.reload();
                    layer.msg('删除成功');
                }
            });
            layer.close(1);
        });
    }

    function sleep(n) {
        var start = new Date().getTime();//定义起bai始时间的毫秒数
        while (true) {
            var time = new Date().getTime();//每次执行循环取得du一次当前时间的毫秒数
            if (time - start > n) {//如果当前时间的毫秒数减去起始时间的毫秒数大于给定的毫秒数，即结束循环
                break;
            }
        }
    }

    // 附件查看
    function aa() {
        var checkStatus = layui.table.checkStatus('test').data;
        var ids = [];
        for (var i = 0; i < checkStatus.length; i++) {
            ids.push(checkStatus[i].id)
        }
        if (ids.length === 0) {
            layer.msg('请选择数据查看');
            return
        }
        var url = "/mOverseeQuestions/downSource?id=" + encodeURI(JSON.stringify(ids));
        $.fileDownload(url, {
            httpMethod: 'GET',
            //同时上传表单数据
            data: '',
            prepareCallback: function (url) {
                $('#down').attr('disabled', false)
                console.log("请稍等！");
            },
            successCallback: function (url) {
                $('#down').attr('disabled', false)
                return false
            },
            failCallback: function (html, url) {
                var json = JSON.parse(html);
                console.log(json);
                $('#down').attr('disabled', false)
            }
        });
        return false
    }
    $('#down').on('click',  function () {
        aa()
    })


    //下面为点击首项选中子项;子项全选,首项选中
    $('#checkAll').on('click', function () {
        if (this.checked) {
            $(this).attr('checked', 'checked')
            $("input[name='childclick']").each(function () {
                this.checked = true;
            });
        } else {
            $(this).removeAttr('checked')
            $("input[name='childclick']").each(function () {
                this.checked = false;
            });
        }
    });

    function childclick() {

        if ($(this).is(":checked") == false) {
            $("#checkAll").prop("checked", false);
        }
        if ($("input[name='childclick']:checked").length == $("input[name='childclick']").length) {
            $("#checkAll").prop("checked", true);
        }
    }

    // 导出excel
    function excel() {

        var type = 'null';
        var year = 'null';
        var branch = 'null';

        if ($("#questionType").val() != null && $("#questionType").val() != "") {
            type = encodeURI(JSON.stringify($("#questionType").val()));
        }
        if ($("#startPatrolTime").val() != null && $("#startPatrolTime").val() != "") {
            year = encodeURI(JSON.stringify($("#startPatrolTime").val()));
        }
        if ($("#branch").val() != null && $("#branch").val() != "") {
            branch = encodeURI(JSON.stringify($("#branch").val()));
        }

        var table2 = layui.table;
        var ids = [];
        $.each($('input[name=\'childclick\']:checkbox'), function () {
            if (this.checked) {
                ids.push($(this).val())
            }
        });
        var form = layui.form;
        if (ids.length > 0) {
            // 选择导出
            ids = JSON.stringify(ids);
            location.href = '/mOverseeQuestions/excelByIds?ids=' + encodeURI(ids);

        } else {
            // 导出全部
            location.href = '/mOverseeQuestions/excel?type=' + type + '&year=' + year + '&branch=' + branch + '&userId=' + userId;

        }


    }

    $("#test4").click(function () {

        layui.use(['table', 'form'], function () {

            var table = layui.table;

            var ids = [];
            $.each($('input[name=\'childclick\']:checkbox'), function () {
                if (this.checked) {
                    ids.push($(this).val())
                }
            });
            var form = layui.form;
            if (ids.length > 1 || ids.length === 0) {
                layer.msg('请选择一条数据查看');

            } else {
                var id = ids[0]

                $.ajax({
                    url: '/mOverseeQuestions/fileList',
                    dataType: 'json',
                    type: 'post',
                    data: {id: id},
                    success: function (data) {
                        if (data.code === 1) {
                            layer.msg('未上传附件');
                        } else {
                            layer.open({
                                type: 1,
                                title: '<div class="layui-icon" style="font-weight: bold;text-align: center"> 附件列表</div>',
                                area: ['80%', '80%'], //宽高
                                content: $('#openProductBox2'),
                                success: function (data) {

                                    table.render({
                                        elem: '#test',
                                        width: '100%'
                                        , method: 'post', //接口http请求类型，默认：get
                                        page: false,
                                        limit: Number.MAX_VALUE,
                                        url: '/mOverseeQuestions/fileList', //?page=1&limit=10（该参数可通过 request 自定义）
                                        where: {id: id},
                                        cols: [[
                                            {
                                                type: 'checkbox'
                                            }, {
                                                field: 'branch', //字段名
                                                title: '单位名称', //标题
                                                width: 200
                                                //fixed: 'left' //固定列
                                            }, {
                                                field: 'question', //字段名
                                                title: '问题项', //标题
                                                width: 260
                                            }, {
                                                field: 'path', //字段名
                                                title: '附件名称', //标题
                                                width: 454
                                            }, {
                                                field: '', title: '操作',
                                                width: 80,
                                                toolbar: '#itemTpl',
                                                fixed: 'right' //固定列
                                            }]
                                        ],
                                        done: function (res, curr, count) {
                                            $('th').css({'font-weight': 'bold'});
                                        }
                                    });
                                }
                            });
                        }
                    }
                })

            }
        });
        layui.use('table', function () {
            var table = layui.table;

            //监听行工具事件
            table.on('tool(test)', function (obj) {
                var checkStatus = layui.table.checkStatus('openProductBox2').data;
                var data = obj.data;
                //console.log(data)
                if (obj.event === 'del') {
                    var s = data.path;
                    location.href = '/mOverseeQuestions/downSource?path=' + s;
                }
                if (obj.event === 'del1') {
                    var id = data.id;
                    $.ajax({
                        url: '/mOverseeQuestions/deletePathOne?id=' + id,
                        type: 'get',
                        success: function () {
                            layer.msg("删除申请已发出", {
                                icon: 1,
                                time: 1000
                            });
                            table.reload("test");
                        }
                    })
                }
                if (obj.event === 'del2') {
                    var id = data.id;
                    $.ajax({
                        url: '/mOverseeQuestions/deletePathTwo?id=' + id,
                        type: 'get',
                        success: function () {
                            layer.msg('删除成功');
                        }
                    })
                }
            });
        });
    })

    var questionId = '';

    var table2;

    $("#searchBt").click(function () {
        example.ajax.reload();
    });

    init()
    $("#open1").click(function () {
        layer.open({
            type: 2
            , title: '单位'
            , shadeClose: true
            , shade: 0.8
            , area: ['500px', '500px']
            , maxmin: true
            , content: 'dept.html'
            , btn: ['确定']
            , yes: function (index, layero) {
                var body = layer.getChildFrame('body', index);
                var iframeWin = window[layero.find('iframe')[0]['name']];
                var checkStatus = iframeWin.layui.table.checkStatus('test');
                if (checkStatus.data.length > 0) {
                    var selectedData = checkStatus.data[0];
                    $("#open1").val(selectedData.branchName);
                    layer.close(index);
                }
            }
        });
    });

    function reload() {
        window.location.reload()
    }


</script>
</body>
</html>


